package com.wang.config;

import com.wang.bean.SwaggerInfo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;

/**
 * @Author wangf
 * @Description TODO
 * @Date 2023/9/9 18:47
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Resource
    private SwaggerInfo swaggerInfo;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(swaggerInfo.getBasePackage()))
                .paths(PathSelectors.any()).build();
    }
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder().title(swaggerInfo.getTitle())
                .contact(new Contact(swaggerInfo.getContactName(),swaggerInfo.getContactUrl(), swaggerInfo.getContactEmail()))
                .version(swaggerInfo.getVersion())
                .description(swaggerInfo.getDescription()).build();
    }
}
